package servlet;

import dao.impl.UserDaoImpl;
import entity.JavaBean;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

public class MyFirstServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        this.doGet(request,response);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        String user = request.getParameter("user");
        String semail = request.getParameter("semail");
        UserDaoImpl userDao = new UserDaoImpl();
        boolean flag=false;
        try {
            List<JavaBean> list = userDao.findUser(user, semail);
            for (JavaBean javaBean : list) {
                if (javaBean.getSname()==user&&javaBean.getSemail()==semail){
                    flag=true;
                }
            }
            if (flag){
                request.getRequestDispatcher("/index4.jsp").forward(request,response);

            }else{
                response.sendRedirect("/index.jsp");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}
